package com.zmn.oms.business.impl.yeyxplus;

import com.zmn.base.common.data.common.dro.tags.TagsDRO;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.consts.GlobalConsts;
import com.zmn.oms.business.interfaces.base.BaseCodeService;
import com.zmn.oms.business.interfaces.yeyxplus.YeyxPlusBService;
import com.zmn.oms.common.constant.CompanyConsts;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 类描述：
 *
 * @author wangxiaokun
 * @since 2022/04/02 11:28
 */
@Slf4j
@Service
public class YeyxPlusBServiceImpl implements YeyxPlusBService {

    // 新言而有信领单管控城市试点
    //@NacosValue(value = "${new.yeyx.cityId:0}", autoRefreshed = true)
    //private String newYeyxCityIdList;

    // 新言而有信领单管控工程师试点
    //@NacosValue(value = "${new.yeyx.masterId:0}", autoRefreshed = true)
    //private String newYeyxMasterIdList;

    /**
     * 公共配置家修匠城市一级分类id
     */
    private Integer JXJ_ONT_TYPE_ID = 100000;

    @Autowired
    private BaseCodeService baseCodeService;

    @Override
    public Boolean isYeyxPilot(Integer companyId, Integer cityId, Integer masterId) {

        // 不是家修匠返回false
        if (!Objects.equals(CompanyConsts.ZMN_JXJ_COMPANY_ID, companyId)) {
            return false;
        }

        // 城市id师傅id为空返回false
        if (NumberUtil.isNullOrZero(cityId) || NumberUtil.isNullOrZero(masterId)) {
            return false;
        }

        List<TagsDRO> list = baseCodeService.listBaseCodeMap(GlobalConsts.PLAT_MARK_YEYX, JXJ_ONT_TYPE_ID, null, null);
        if (CollectionUtil.isNullOrEmpty(list)) {
            return false;
        }

        List<Integer> cityList = list.stream().map(TagsDRO::getThreeTypeId).collect(Collectors.toList());
        // 三级分类id是0，开通全国城市
        if (cityList.contains(GlobalConsts.NONE) || cityList.contains(cityId)) {
            return true;
        }

        return false;

        /*boolean isPilot = false;

        // 优先判断城市
        if (StringUtil.isNotBlank(newYeyxCityIdList)) {
            if (Objects.equals(newYeyxCityIdList, "all")) {
                isPilot = true;
            } else {
                List<String> cityIdList = Arrays.asList(newYeyxCityIdList.split(","));
                if (cityIdList.contains(String.valueOf(cityId))) {
                    isPilot = true;
                }
            }
        }

        // 工程师
        if (!isPilot && StringUtil.isNotBlank(newYeyxMasterIdList)) {
            // 所有工程师开启服务分试点配置
            List<String> cityIdList = Arrays.asList(newYeyxMasterIdList.split(","));
            if (cityIdList.contains(String.valueOf(masterId))) {
                isPilot = true;
            }
        }
        return isPilot;*/
    }
}
